/*
 * Copyright (c) 2025 Industrial Software Feature Database
 */
package com.comac.ins.isfd.util.bdfparser.enums;

import com.comac.ins.common.core.utils.StringUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * bdf文件类型
 *
 * @author hxloongs
 * @date 2025-02-12
 */
@AllArgsConstructor
@Getter
public enum ContentTypeEnum {
    INDEX("index", "机型索引文件"),
    NORMAL("normal", "普通文件"),
    OTHER("other", "其他文件");
    private final String value;
    private final String desc;

    public static String getDescByValue(String value) {
        ContentTypeEnum contentTypeEnum = forValue(value);
        if (contentTypeEnum == null) {
            return null;
        }
        return contentTypeEnum.getDesc();
    }

    public static ContentTypeEnum forValue(String value) {
        if (StringUtils.isBlank(value)) {
            return null;
        }
        for (ContentTypeEnum contentTypeEnum : ContentTypeEnum.values()) {
            if (contentTypeEnum.getValue().equals(value)) {
                return contentTypeEnum;
            }
        }
        return null;
    }

    public static ContentTypeEnum forDesc(String desc) {
        if (desc == null) {
            return null;
        }
        for (ContentTypeEnum contentTypeEnum : ContentTypeEnum.values()) {
            if (desc.equals(contentTypeEnum.getDesc())) {
                return contentTypeEnum;
            }
        }
        return null;
    }
}
